import Vue from 'vue'
import VueRouter from 'vue-router'
import bookshop from '../views/bookshop.vue'


Vue.use(VueRouter)

const routes = [

  {
    path:"/",
    redirect: "/bookshop"
  },

  {
    path: "/my",
    name: "my",
    component: ()=>import("../views/my.vue"),
    beforeEnter:(to,from,next)=>{
      let login = window.localStorage.getItem("token");
      // 判断没有值
      if(!login){
        next("/login");
        
      }else{
        next()
      }

    }
  },
  {
    path:"/login",
    name:"login",
    component:()=>import("../components/base/login.vue")
  },


  {
    path: "/bookshop",
    name: "bookshop",
    component: bookshop
    
  },
 

  {
    path: "/category",
    name: "category",
    component: ()=>import("../views/category.vue")
  },

  

  {
    path:"/bookrack",
    name:"bookrack",
    component:()=>import("../views/bookrack.vue")
  },

  // {
  //   path: "/my",
  //   name: "my",
  //   component: ()=>import("../views/my.vue")
  // },
  {
    path:"/search",
    name:"search",
    component: ()=>import("../views/search.vue")
  },
  {
    path:"/sorter",
    name:"sorter",
    component: ()=>import("../views/sorter.vue")
  },
  {
    path:"/details",
    name:"details",
    component:()=>import("../views/details.vue")

  },
  {
    path:"/introduce",
    name:"introduce",
    component:()=>import("../views/introduce.vue")
  },
  {
    path:"/review",
    name:"review",
    component:()=>import("../views/review.vue")
  },
 



  // {
  //   path: '/',
  //   name: 'Home',
  //   component: Home
  // },
  // {
  //   path: '/about',
  //   name: 'About',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  // }
]

const router = new VueRouter({
  routes,
  linkActiveClass:"active"
})

export default router
